<?php
class BusinessmeetingsController extends AppController {

    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index() {
        $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Business Meetings List";
        $in_record_data = $this->Businessmeeting->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }

    
    public function add(){
    $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Add Business Meetings";
     if($_POST){
       // pr($_POST);
        $data['Businessmeeting'] = array(
            'buzmid' => $_POST['buzmid'],
            'buzmdate' => $_POST['buzmdate'],
            'chair' => $_POST['chair'],
            'recorder' => $_POST['recorder'],
            'topic' => $_POST['topic'],
            'motioned' => $_POST['motioned'],
            'seconded' => $_POST['seconded'],
            'mpresent' => $_POST['mpresent'],
            'msupport' => $_POST['msupport'],
            'magainst' => $_POST['magainst'],
            'neutral' => $_POST['neutral'],
            'conclude' => $_POST['conclude']
        );

        if(!$this->Businessmeeting->save($data)){
            $this->Session->setFlash('Error Saving Business Meeting');
        }else{
             $this->Session->setFlash('Business Meetings Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg'));
}
    
    // A functin to delete Businessmeeting
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Business Meetings');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Businessmeeting->delete($id)) 
    {
        $this->Session->setFlash('Business Meetings Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Business Meeting Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Personal Details
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Businessmeeting.id' => $record_id);
    $record = $this->Businessmeeting->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Edit Business Meeting";
     if($_POST){
        //pr($_POST);
        $data['Businessmeeting'] = array(
            'bmid' => $_POST['bmid'],
            'action' => $_POST['action'],
            'mpresent' => $_POST['mpresent'],
            'minsupport' => $_POST['minsupport'],
            'moppose' => $_POST['moppose'],
            'monfence' => $_POST['monfence'],
            'executioner' => $_POST['executioner']
        );

        if(!$this->Businessmeeting->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Pernal Detail Records
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $businessmeeting = $this->Businessmeeting->findById($id);
    if (!$businessmeeting) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('Businessmeeting', $businessmeeting);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('businessmeeting.id' => $record_id);
    $record = $this->businessmeeting->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>